package com.linzm.leetcode.primary.exercises1_20230114;

/**
 * @Author zimingl
 * @Date 2023/1/15 16:34
 * @Description: 回文数
 *
 * 做法：回文， left、 right
 */
public class Demo20_9 {

    public static void main(String[] args) {
        Demo20_9 demo20_9 = new Demo20_9();
        int num = 1234321;
        boolean palindrome = demo20_9.isPalindrome(num);
        System.out.println(palindrome);
    }

    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        String string = "" + x;
        int right = string.length() - 1;
        for (int left = 0; left < right; ++left) {
            if (string.charAt(left) != string.charAt(right)) {
                return false;
            }
            right--;
        }
        return true;
    }
}
